#include <reg52.H>
#include "led.h"
#include "Init.h"
#include "Key.h"
#include "smg.h"
#include "onewire.h"

///////////////////////////
sfr AUXR = 0x8e;
unsigned char Key_up,Key_down,Val_old,Val;//键盘扫描
unsigned char Key_Slow;//键盘减速
unsigned int Smg_Slow;//数码管减速
unsigned int dat18b20;//温度参数
unsigned char  smg_dis_mod;

unsigned char smgpos;
unsigned char LED[] = {0,1,0,1,0,1,0,1};
unsigned char smgdat[8] = {0,10,10,10,10,10,10,10};
unsigned char smgpoint[8] = {0,0,0,0,0,0,0,0};	

////////////////////////////
//处理键盘
void CopyKey()
{
	if(Key_Slow) 
		return ;
	Key_Slow = 1;
	Val = ScanKey();
	Key_down = Val&(Val_old ^ Val);
	Key_up = ~(Val&(Val_old ^ Val));
	Val_old = Val;
}

//信息处理函数

void CopySmg()
{
	if(Smg_Slow) return;
	Smg_Slow = 1;
	
	dat18b20 = Ds18b20();
	
	switch(smg_dis_mod)
	{
		case 0:
			smgdat[0] = 15;
			smgdat[4] = dat18b20/100%10;
			smgdat[5] = dat18b20%100/10;
			smgdat[6]	= dat18b20%10;
			smgdat[7] = 15;
			smgpoint[5] = 1;
			break;
		case
	}
}	
	
void CopyLED()
{

}



//定时器0



//定时器功能
void Timer0_Init(void)		//1毫秒@11.0592MHz
{
	AUXR &= 0x7F;			//定时器时钟12T模式
	TMOD &= 0xF0;			//设置定时器模式
	TL0 = 0x66;				//设置定时初始值
	TH0 = 0xFC;				//设置定时初始值
	TF0 = 0;				//清除TF0标志
	TR0 = 1;				//定时器0开始计时




	EA = 1;
	ET0 = 1;

}

void Delay(unsigned int t)
{
while(t--);
}

void ServerTimer0() interrupt 1
{
	if(++Key_Slow == 10)  Key_Slow=0;
	if(++Smg_Slow == 500) Smg_Slow = 0;
	if(++smgpos == 8) smgpos = 0;
	SMG_Bit(smgpos,smgdat[smgpos],smgpoint[smgpos]);
	Delay(100);
	Led_Dis(smgpos,LED[smgpos]);
}
//
void delay1(unsigned int t)
{
	while(t--);
}

void main()
{
	Ds18b20();
	delay1(750);
	Sys_Init();
	Timer0_Init();
	while(1)
	{
		CopyKey();
		CopySmg();
		CopyLED();
	}
	
	
}



float DS18B20()
{
	unsigned LOW,HON;
	init();
	Write(0xcc);
	0x44;
	
	init();
	0xcc;
	be;
	Low = read;
	high = read;
	
	Temp = ((High <<8) | low)/16;

	return temp;
	
	
}
